
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;

public class RegexBubbleSort {

	public static void main(String[] args) {

		FileRegex first = new FileRegex("text.txt");
		ArrayList list = BubbleSort.bubbleSort(first.getMatchesFromFile());

		try {
			File file = new File("result.txt");
			if (!file.exists()) {
				file.createNewFile();
			}
			FileWriter fstream = new FileWriter(file);
			BufferedWriter out = new BufferedWriter(fstream);
			Iterator itr = list.iterator();
			while (itr.hasNext()) {
				out.write((String) itr.next());
				out.newLine();
			}
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
